package com.ruoyi.web.controller.enterprise;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.enterprise.domain.EnterpriseArchive;
import com.ruoyi.enterprise.service.IEnterpriseArchiveService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业基本信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/enterprise/info")
public class EnterpriseArchiveController extends BaseController
{
    @Autowired
    private IEnterpriseArchiveService enterpriseArchiveService;

//    @Autowired
//    private ISysChinaService sysChinaService;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询企业基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnterpriseArchive enterpriseArchive)
    {
        startPage();
        List<EnterpriseArchive> list = enterpriseArchiveService.selectEnterpriseArchiveList(enterpriseArchive);
        return getDataTable(list);
    }

    /**
     * 导出企业基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:info:export')")
    @Log(title = "企业基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EnterpriseArchive enterpriseArchive)
    {
        List<EnterpriseArchive> list = enterpriseArchiveService.selectEnterpriseArchiveList(enterpriseArchive);
        ExcelUtil<EnterpriseArchive> util = new ExcelUtil<EnterpriseArchive>(EnterpriseArchive.class);
        return util.exportExcel(list, "企业基本信息数据");
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<EnterpriseArchive> util = new ExcelUtil<EnterpriseArchive>(EnterpriseArchive.class);
        return util.importTemplateExcel("企业数据");
    }


    /**
     * 获取企业基本信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:info:query')")
    @GetMapping(value = "/{epId}")
    public AjaxResult getInfo(@PathVariable("epId") Long epId)
    {
        return AjaxResult.success(enterpriseArchiveService.selectEnterpriseArchiveById(epId));
    }

    /**
     * 新增企业基本信息
     */
    @RepeatSubmit
   // @PreAuthorize("@ss.hasPermi('enterprise:info:add')")
    @Log(title = "企业基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnterpriseArchive enterpriseArchive)
    {
        return toAjax(enterpriseArchiveService.insertEnterpriseArchive(enterpriseArchive));
    }

    /**
     * 修改企业基本信息
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:info:edit')")
    @Log(title = "企业基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnterpriseArchive enterpriseArchive)
    {
        return toAjax(enterpriseArchiveService.updateEnterpriseArchive(enterpriseArchive));
    }

    /**
     * 删除企业基本信息
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:info:remove')")
    @Log(title = "企业基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{epIds}")
    public AjaxResult remove(@PathVariable Long[] epIds)
    {
        return toAjax(enterpriseArchiveService.deleteEnterpriseArchiveByIds(epIds));
    }

}
